﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityData;
using CoreData;

namespace Services
{
   public class Subject_TeacherService
    {
         readonly Subject_TeacherEntity entity;

         public Subject_TeacherService()
       {
           this.entity = new Subject_TeacherEntity();

       }

       #region Main Method

       /// <summary>
       /// Save 
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public long Save(object _model)
       {
           try
           {
               var id = long.Parse(_model.GetType().GetProperty("ID").GetValue(_model, null).ToString());
               if (id == 0)
               {
                   return entity.Save((CoreData.Subject_Teacher)_model, Table.Subject_Teacher.ToString());
               }
               else
               {
                   return entity.Update((CoreData.Subject_Teacher)_model, Table.Subject_Teacher.ToString());
               }
           }
           catch { return -1; }
       }

       /// <summary>
       /// Get by ID
       /// </summary>
       /// <param name="_id"></param>
       /// <returns></returns>
       public CoreData.Subject_Teacher GetByID(long _id)
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetSubject_Teacher," Subject_Teacher.ID="+_id)).ToList()[0];
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Subject_Teacher> GetList()
       {
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetSubject_Teacher, "Subject_Teacher.IsDeleted='false'")).ToList();
           }
           catch { return null; }

       }

       /// <summary>
       /// Get List with Linq
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Subject_Teacher> GetListByLINQ(Func<CoreData.Subject_Teacher, Boolean> _where)
       {
           try
           {
               return entity.GetMany(_where, Table.Subject_Teacher.ToString()).ToList();
           }
           catch { return null; }
       }
       /// <summary>
       /// Get One with Linq
       /// </summary>
       /// <returns></returns>
       public CoreData.Subject_Teacher GetOneByLINQ(Func<CoreData.Subject_Teacher, Boolean> _where)
       {
           try
           {
               return entity.Get(_where, Table.Subject_Teacher.ToString());
           }
           catch { return null; }
       }

       /// <summary>
       /// Get List with search string
       /// </summary>
       /// <returns></returns>
       public IList<CoreData.Subject_Teacher> GetList(string _searchstring)
       {
           //search theo tieu chi nao do         
           try
           {
               return entity.GetByCusTomSQL(String.Format(SQLCommand.GetSubject_Teacher, "Subject_Teacher.IsDeleted='false' and " + _searchstring)).ToList();
           }
           catch { return null; }
       }


       /// <summary>
       /// Delete
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public bool Delete(object _model)
       {
           try
           {
               entity.Delete((CoreData.Subject_Teacher)_model, Table.Subject_Teacher.ToString());
               return true;
           }
           catch { return false; }
       }

       /// <summary>
       /// Delete a object by hidden
       /// </summary>
       /// <param name="_model"></param>
       /// <returns></returns>
       public bool UpdateIsDelete(object _model)
       {
           try
           {
               var obj = (CoreData.Subject_Teacher)_model;
               obj.IsDeleted = true;
               entity.Update(obj, Table.Subject_Teacher.ToString());
               return true;
           }
           catch { return false; }
       }
       #endregion



        #region Other Method



        #endregion 
    }
}
